home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / osr5 / sco / scripts / mail / mbiff < prev    next >
Encoding:
Korn shell script  |  1997-08-26  |  2.5 KB  |  91 lines

  1. #!/bin/ksh
  2. # @(#) mbiff.ksh 1.2 95/08/25
  3. # mbiff: turn mail notification on or off.    
  4. # 92/02/15 john h. dubois iii (john@armory.com)
  5. # 92/03/25 rcvalert broken under 3.2v4; use mailalert instead
  6. #          (modified so that alertprog is only given once so it can be changed)
  7. # 92/09/26 Remove ksh dependence
  8. # 93/12/04 Changed name from notify to mbiff; notify is a tcsh builtin
  9. # 94/07/14 exec alertprog to avoid needless shell fork.
  10. #          Put user name on mailalert cmd line for efficiency.
  11. # 95/02/04 Added 'status' command.
  12.  
  13. alertprog=/usr/local/bin/mailalert
  14. expression="^\*[     ][     ]*-[     ].*[     ](exec )?$alertprog"
  15.  
  16. # status: returns zero if mail notification is enabled; nonzero if not.
  17. status() {
  18.     egrep "$expression" $HOME/.maildelivery > /dev/null 2>&1
  19. }
  20.  
  21. function help {
  22.     echo \
  23. "$name: Turn immediate mail notification on or off.  If immediate mail
  24. notification is on, any time that a mail message is received for you while
  25. you are logged in a message will be printed to your screen regardless of what
  26. you are doing.
  27. Usage: $name [on|off|status]
  28. $name          tells you whether notification is on or off.
  29. $name status   prints a more terse notification status.
  30. $name on       turns on immediate notification of new mail.
  31. $name off      turns off immediate notification of new mail.
  32.  
  33. Notification status does not change between logins (when you turn
  34. it on or off, it will remain on or off until you change it again)."
  35.     exit 0
  36. }
  37.  
  38. if [[ "${0##*/}" = biff ]]; then
  39.     echo 'Use "mbiff" to turn on immediate notification of new mail.'
  40.     name=mbiff
  41.     help
  42. fi
  43.  
  44. name=${0##*/}
  45.  
  46. cd
  47. case "$1" in
  48. on)
  49.     if status; then
  50.     echo "Immediate mail notification was already on."
  51.     else
  52.     # preserve old .maildelivery permissions
  53.     [ -f .maildelivery ]
  54.     hasmaildelivery=$?
  55.     [ $hasmaildelivery = 0 ] && /bin/cp .maildelivery .maildelivery-
  56.     # put alert line at top of .maildelivery
  57.     echo \
  58. "*    -    pipe    R    exec $alertprog $USER" > .maildelivery
  59.     [ $hasmaildelivery = 0 ] && cat .maildelivery- >> .maildelivery
  60.     echo "Immediate mail notification is now on."
  61.     fi
  62.     ;;
  63. off)
  64.     if status; then
  65.     # preserve old .maildelivery permissions
  66.     /bin/cp .maildelivery .maildelivery-
  67.     egrep -v "$expression" .maildelivery- > .maildelivery
  68.     echo "Immediate mail notification is now off."
  69.     else
  70.     echo "Immediate mail notification was already off."
  71.     fi
  72.     ;;
  73. status)
  74.     if status; then
  75.     echo "on"
  76.     else
  77.     echo "off"
  78.     fi
  79.     ;;
  80. "")
  81.     if status; then
  82.     echo "Immediate mail notification is on."
  83.     else
  84.     echo "Immediate mail notification is off."
  85.     fi
  86.     ;;
  87. *)
  88.     help
  89.     ;;
  90. esac
  91.